package com.example.fairytset;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class PicFragment extends Fragment implements View.OnClickListener {
    private TextView textview1;
    private TextView textview2;
    private TextView textview3;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //创建界面MsgFragment
        View view = inflater.inflate(R.layout.picture_fragment, container, false);
        bindViews(view);
        return view;

    }

    private void bindViews(View view) {
        textview1 = view.findViewById(R.id.textview1);
        textview2 = view.findViewById(R.id.textview2);
        textview3 = view.findViewById(R.id.textview3);

        textview1.setOnClickListener(this);
        textview2.setOnClickListener(this);
        textview3.setOnClickListener(this);

    }

    private void setSelected(){
        textview1.setSelected(false);
        textview2.setSelected(false);
        textview3.setSelected(false);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        textview1.performClick();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.textview1:
                setSelected();
                textview1.setSelected(true);
                replacFragment(new HeadFragment());
                break;
            case R.id.textview2:
                setSelected();
                textview2.setSelected(true);
                replacFragment(new NestedmapFragment());
                break;
            case R.id.textview3:
                setSelected();
                textview3.setSelected(true);
                replacFragment(new WallpaperFragment());
                break;
            default:
                break;

        }
    }
    private void replacFragment (Fragment fragment){
        FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fra2, fragment);
        transaction.commit();
    }
}